import csv
from datetime import datetime
import requests

def calc_score():
    with open('/Users/zhanglei/Desktop/input/test_20181113.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter='\t')
        line_count = 0
        for row in csv_reader:
            imei = row[0]
            apply_time = row[1]
            apply_dt = datetime.strptime(apply_time, '%Y%m%d').strftime("%s")

            # url = 'http://127.0.0.1:8000/app/calc_score/?imei=%s&apply_time=%s' % (imei, apply_dt)
            url = 'http://itfinimei.loan.sogou.com/app/calc_score/?imei=%s&apply_time=%s' % (imei, apply_dt)
            reponse=requests.get(url)
            print(imei, apply_dt, reponse.status_code, line_count, reponse.json()['mesg'])
            line_count += 1

def get_score():
    with open('/Users/zhanglei/Desktop/input/test_20181113.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter='\t')
        line_count = 0
        for row in csv_reader:
            imei = row[0]
            apply_time = row[1]
            apply_dt = datetime.strptime(apply_time, '%Y%m%d').strftime("%s")
            # url = 'http://127.0.0.1:8000/app/get_score/?imei=%s&apply_time=%s' % (imei, apply_dt)
            url = 'http://itfinimei.loan.sogou.com/app/get_score/?imei=%s&apply_time=%s' % (imei, apply_dt)
            reponse=requests.get(url)
            print(imei, apply_dt, reponse.status_code, line_count, reponse.json()['mesg'])
            line_count += 1

if __name__ == '__main__':
    # calc_score()
    get_score()